Ext.define('PJ.view.messagemanagement.ChoisedList', {
    extend: 'AM.default.DefaultList',
    alias: ['widget.messagemanagementChoisedList'],
    isHavePage: false,
    initComponent: function(){
        this.columns = [{
            header: '登录号',
            dataIndex: 'loginID',
            width:'25%',
            renderer: function(value, meta, record){
                meta.tdAttr = 'data-qtip="' + value + '"';
                return value;
            }
        },{
            header: '姓名',
            dataIndex: 'userName',
            width:'30%',
            renderer: function(value, meta, record){
                meta.tdAttr = 'data-qtip="' + value + '"';
                return value;
            }
        },{
            header: '所属部门',
            dataIndex: 'deptName',
            width:'40%',
            renderer: function(value, meta, record){
                meta.tdAttr = 'data-qtip="' + value + '"';
                return value;
            }
        },{
            dataIndex: 'userId',
			hidden : true,
            renderer: function(value, meta, record){
                meta.tdAttr = 'data-qtip="' + value + '"';
                return value;
            }
        }];
        this.store = Ext.create('PJ.' + prototype + '.messagemanagement.ChoisedList', {
            isLoad: false
        });
        this.loadType = gj_onlineLearning_constant.loadType;
        this.callParent(arguments);
    },
    onDeleteClick: function(button){
        var me = this;
        var records = me.getSelectionModel().getSelection();
        var store = me.getStore();
        for (i in records) {
            store.remove(records[i]);
        }
        store.reload();
    },
    listeners: {
        viewready: function(){
            this.addDocked([{
                xtype: 'toolbar',
                dock: 'top',
                displayInfo: true,
                items: [this.deleteButton]
            }]);
            // 触发权限过滤事件
            this.fireEvent("permission", this);
            var me = this;
            var name1 = this.up("container").receiveUserNames.getValue();
            var id1 = this.up("container").receiveUserIds.getValue();
            var loginId1=this.up("container").loginIds.getValue();
            var deptName1=this.up("container").deptNames.getValue();
            if (name1!=""&&id1!=""&&loginId1!=""&deptName1!="") {
	            var name = name1.split(',');
	            var id = id1.split(',');
	            var lid=loginId1.split(',');
	            var dname=deptName1.split(',');
                var model;
                var record = new Array();
                for (i in id) {
                	if(isNaN(i)){
                		continue;
                	}
                    model = Ext.create("PJ.model.messagemanagement.PreChoisedList");
                    model.set({
                        //列表上的所有字段属性，赋值空
                        "userName": name[i],
                        "userId": id[i],
                        "loginID":lid[i],
                        "deptName":dname[i]
                    });
                    model.commit();//提交model，如果添加此句则列表上不会再显示左上角修改后的标识符
                    record.push(model);
                }
                var store = me.getStore();
                store.each(function(datas){
                    for (var i = 0; i < record.length; i++) {
                        if (datas.data.userId == record[i].data.userId) {
                            record.splice(i, 1);
                            i--;
                        }
                    }
                });
                store.add(record);//将刚刚新建的空数组添加到列表中
            }
        }
    }
});
